package net.nalis.util.mail;

import java.io.IOException;
import java.util.Properties;

import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.URLName;
import javax.mail.internet.MimeMessage;

public class MailUtils {
    public static void main(String[] args) throws MessagingException, IOException {
        Properties props = new Properties();
        props.setProperty("mail.smtp.host", "mail.sina.com");
        props.setProperty("mail.smtp.auth", "false");
        Session session = Session.getDefaultInstance(props,null);
        URLName urlname = new URLName("pop3","mail.sina.com",110,null,"111@sina.com","");
        
        Store store = session.getStore(urlname);
        store.connect();
        Folder folder = store.getFolder("INBOX");
        folder.open(Folder.READ_ONLY);
        Message msgs[] = folder.getMessages();
        int count = msgs.length;
        System.out.println("Message Count:"+count);
        ReciveMail rm = null;
        for(int i=0;i<count;i++){
            rm = new ReciveMail((MimeMessage) msgs[i]);
            if(!(rm.getSubject().contains("工资") || rm.getSubject().contains("薪酬"))){
            	continue;
            }
            rm.recive(msgs[i],i);;
        }
        System.out.println("---------------------------分割线-----------------------");
    }
}
